package megrez.common.jpa;

import javax.persistence.Column;
import javax.persistence.EntityListeners;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.Version;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

/**
 * 实体, 包括：包括：审计，主键版本信息
 *  
 * @author Lucky Yang
 * @since 0.0.1
 */
@Setter
@Getter
@ToString
@EqualsAndHashCode(onlyExplicitlyIncluded = true, callSuper = false)
@MappedSuperclass
@EntityListeners({IdEntityListener.class})
public abstract class AbstractIdAuditingEntity extends AbstractAuditingEntity implements IdEntity {
    @Id
    @EqualsAndHashCode.Include
    @ToString.Include
    @Column(updatable = false, nullable = false, unique = true)
    private Long id;
    @Version
    @Column(nullable = false)
    private Integer version;

    @Override
    public boolean isPersist() {
        return this.id != null;
    }  
}
